package com.ruoyi.web.controller.ring;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ring.domain.RingSleepType;
import com.ruoyi.ring.service.IRingSleepTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 睡眠类型Controller
 * 
 * @author liuwp
 * @date 2025-08-27
 */
@RestController
@RequestMapping("/ring/ring_sleep_type")
public class RingSleepTypeController extends BaseController
{
    @Autowired
    private IRingSleepTypeService ringSleepTypeService;

    /**
     * 查询睡眠类型列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:list')")
    @GetMapping("/list")
    public TableDataInfo list(RingSleepType ringSleepType)
    {
        startPage();
        List<RingSleepType> list = ringSleepTypeService.selectRingSleepTypeList(ringSleepType);
        return getDataTable(list);
    }

    /**
     * 导出睡眠类型列表
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:export')")
    @Log(title = "睡眠类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RingSleepType ringSleepType)
    {
        List<RingSleepType> list = ringSleepTypeService.selectRingSleepTypeList(ringSleepType);
        ExcelUtil<RingSleepType> util = new ExcelUtil<RingSleepType>(RingSleepType.class);
        util.exportExcel(response, list, "睡眠类型数据");
    }

    /**
     * 获取睡眠类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ringSleepTypeService.selectRingSleepTypeById(id));
    }

    /**
     * 新增睡眠类型
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:add')")
    @Log(title = "睡眠类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RingSleepType ringSleepType)
    {
        return toAjax(ringSleepTypeService.insertRingSleepType(ringSleepType));
    }

    /**
     * 修改睡眠类型
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:edit')")
    @Log(title = "睡眠类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RingSleepType ringSleepType)
    {
        return toAjax(ringSleepTypeService.updateRingSleepType(ringSleepType));
    }

    /**
     * 删除睡眠类型
     */
    @PreAuthorize("@ss.hasPermi('ring:ring_sleep_type:remove')")
    @Log(title = "睡眠类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ringSleepTypeService.deleteRingSleepTypeByIds(ids));
    }
}
